﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Trippy.CollidableGameComponents;
using Trippy.CollidableGameComponents.Agents;
using Trippy.Levels;
using Trippy.CollidableGameComponents.Projectiles;

namespace Trippy.Abilities
{
    class Rocket : Ability
    {
        public Rocket(Level level)
            : base(level)
        {
            name = "Rocket";
            icon = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Ability Icons/rocket");
        }

        public override void OnAdd()
        {
            State = AbilityState.Available;
        }

        public override void OnActivate()
        {
            Missile m = new Missile(CurrentLevel);
            if (CurrentLevel.Hero.Sprite.CurrentMode == 0) //facing left
            {
                m.Position = new Vector2(CurrentLevel.Hero.BoundingBox.Left - 40f, CurrentLevel.Hero.Position.Y);
                m.Velocity = new Vector2(-100f, 0f);
                m.Acceleration = new Vector2(-900f, 0f);
            }
            else
            {
                m.Position = new Vector2(CurrentLevel.Hero.BoundingBox.Right + 40f, CurrentLevel.Hero.Position.Y);
                m.Velocity = new Vector2(100f, 0f);
                m.Acceleration = new Vector2(900f, 0f);
            }
            m.MarkForAddition();

            SetTimer(3.0f);
            State = AbilityState.Unavailable;
            base.OnActivate();
        }

        protected override void OnTimer()
        {
            State = AbilityState.Available;
            base.OnTimer();
        }
    }

    class LimitedRockets : Rocket
    {
        protected int Uses;

        public LimitedRockets(Level level, int uses)
            : base(level)
        {
            name = "Limited Rocket";
            icon = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Ability Icons/rocket");
            Uses = uses;
        }

        public override void OnActivate()
        {
            Uses--;
            if (Uses <= 0)
                CurrentLevel.Hero.RestoreAbility();
            base.OnActivate();
        }

        public override void OnDraw(SpriteBatch sb, Rectangle r)
        {
            base.OnDraw(sb, r);
            sb.DrawString(font, Uses.ToString(), new Vector2(r.X + 7, r.Y + r.Height - 20), CurrentLevel.UIColor);
        }
    }
}